﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.EndCaptivityLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class EndCaptivityLogEntry : LogEntry, IEncyclopediaLog, IChatNotification
  {
    [SaveableField(730)]
    public readonly IFaction CapturerMapFaction;
    [SaveableField(731)]
    public readonly Hero Prisoner;

    internal static void AutoGeneratedStaticCollectObjectsEndCaptivityLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.CapturerMapFaction);
      collectedObjects.Add((object) this.Prisoner);
    }

    internal static object AutoGeneratedGetMemberValueDetail(object o)
    {
      return (object) ((EndCaptivityLogEntry) o).Detail;
    }

    internal static object AutoGeneratedGetMemberValueCapturerMapFaction(object o)
    {
      return (object) ((EndCaptivityLogEntry) o).CapturerMapFaction;
    }

    internal static object AutoGeneratedGetMemberValuePrisoner(object o)
    {
      return (object) ((EndCaptivityLogEntry) o).Prisoner;
    }

    [SaveableProperty(732)]
    public EndCaptivityDetail Detail { get; private set; }

    public EndCaptivityLogEntry(
      Hero prisoner,
      IFaction capturerMapFaction,
      EndCaptivityDetail detail)
    {
      this.CapturerMapFaction = capturerMapFaction;
      this.Prisoner = prisoner;
      this.Detail = detail;
    }

    public override string ToString() => this.GetEncyclopediaText().ToString();

    public bool IsVisibleNotification => true;

    public TextObject GetEncyclopediaText() => this.GetNotificationText();

    public bool IsVisibleInEncyclopediaPageOf<T>(T obj) where T : MBObjectBase
    {
      return (object) obj == this.Prisoner || (object) obj == this.Prisoner.Clan;
    }

    public override ChatNotificationType NotificationType
    {
      get => this.MilitaryNotification((IFaction) this.Prisoner.Clan, (IFaction) null);
    }

    public TextObject GetNotificationText()
    {
      TextObject parent = new TextObject("{=6u3t174w}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} is now free.");
      switch (this.Detail)
      {
        case EndCaptivityDetail.Ransom:
          parent = new TextObject("{=pX0MgdZA}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has been ransomed from the {CAPTURER_FACTION}.");
          break;
        case EndCaptivityDetail.ReleasedAfterPeace:
          parent = new TextObject("{=wlhJGG0q}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has been freed because of a peace declaration.");
          break;
        case EndCaptivityDetail.ReleasedAfterBattle:
          parent = new TextObject("{=hp4jLl3M}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has been released after battle.");
          break;
        case EndCaptivityDetail.ReleasedAfterEscape:
          parent = new TextObject("{=krTrNonp}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has escaped from captivity.");
          break;
        case EndCaptivityDetail.Death:
          parent = new TextObject("{=XbQFAKUz}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has died while being held captive by the {CAPTURER_FACTION}.");
          break;
        case EndCaptivityDetail.ReleasedByCompensation:
          parent = new TextObject("{=krTrNonp}{PRISONER_LORD.LINK}{?PRISONER_LORD_HAS_FACTION_LINK} of the {PRISONER_LORD_FACTION_LINK}{?}{\\?} has escaped from captivity.");
          break;
      }
      Clan clan = this.Prisoner.Clan;
      if ((clan != null ? (!clan.IsMinorFaction ? 1 : 0) : 0) != 0)
      {
        parent.SetTextVariable("PRISONER_LORD_FACTION_LINK", this.Prisoner.MapFaction.EncyclopediaLinkWithName);
        parent.SetTextVariable("PRISONER_LORD_HAS_FACTION_LINK", 1);
      }
      StringHelpers.SetCharacterProperties("PRISONER_LORD", this.Prisoner.CharacterObject, parent);
      if (this.CapturerMapFaction != null)
        parent.SetTextVariable("CAPTURER_FACTION", this.CapturerMapFaction.InformalName);
      return parent;
    }

    public override void GetConversationScoreAndComment(
      Hero talkTroop,
      bool findString,
      out string comment,
      out ImportanceEnum score)
    {
      score = ImportanceEnum.Zero;
      comment = "";
      if (talkTroop != this.Prisoner || !talkTroop.IsPlayerCompanion)
        return;
      if (this.Detail == EndCaptivityDetail.Ransom)
      {
        score = ImportanceEnum.VeryImportant;
        comment = "str_comment_captivity_release_companion_ransom";
      }
      else
      {
        score = ImportanceEnum.VeryImportant;
        comment = "str_comment_captivity_release_companion";
      }
    }
  }
}
